def text_to_number(text: str):
    numbers = {
        "zero": "0",
        "one": "1",
        "two": "2",
        "three": "3",
        "four": "4",
        "five": "5",
        "six": "6",
        "seven": "7",
        "eight": "8",
        "nine": "9"
    }
    try:
        number = int("".join([numbers[num] for num in text.split()]))
        if 100 <= number <= 999:
            return number
        else:
            return -1
    except KeyError:
        return -1


def is_prime(num: int):
    if num <= 1 or num % 2 == 0:
        return False
    for i in range(3, int(num ** 0.5) + 1, 2):
        if num % i == 0:
            return False
    return True


def near_number(num, min_num, max_num):
    if num - min_num == max_num - num:
        return min(min_num, max_num)
    elif num - min_num < max_num - num:
        return min_num
    else:
        return max_num


def prime_number(number: int):
    if number == -1:
        return "Wrong input"

    min_prime = 0
    for i in range(97, number + 1):
        if is_prime(i):
            if i > min_prime:
                min_prime = i

    max_prime = 999
    for i in range(1009, number - 1, -1):
        if is_prime(i):
            if i < max_prime:
                max_prime = i

    result = near_number(number, min_prime, max_prime)
    return result


my_text = input()
print(prime_number(text_to_number(my_text)))
